import csv

# 打开CSV文件
with open("test.csv", mode="r") as csvfile:
    # 创建一个csv.reader对象
    csv_reader = csv.reader(csvfile)

    # 读取表头标识
    idx_buf = next(csv_reader)

    # 获取time和cpu_percent的列索引号
    time_idx = idx_buf.index("time")
    cpu_idx = idx_buf.index("cpu_percent")
    
    # 访问不存在的index
    data_idx = -1
    try:
        data_idx = idx_buf.index("data")
    except Exception as e:
        print(e)
    print(f"time_idx: {time_idx}, cpu_idx: {cpu_idx}, data_idx: {data_idx}")

""" 
time_idx: 0, cpu_idx: 1
"""
